﻿using System;
using System.Linq;
using Lari.Framework.Utility;
using Lari.Services.Data;

namespace Lari.DataAccess
{
    public static class CoreServiceDataAccess
    {

/*
        private static string CurrentUser
        {
            get
            {
                if (HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated)
                    return HttpContext.Current.User.Identity.Name;

                return null;
            }
        }
*/

        public static Employee Authenticate(string userId, string password, LariDbContext db)
        {
            if (db == null) throw new ArgumentNullException("db");
            
            var temPassword = Encryption.Encrypt(password);
            return db.Employees.Include("User.Role.RoleAccesses").SingleOrDefault(s => s.User.UserId == userId.Trim() && s.User.Password == temPassword && s.Active);
        }

        
    }
}
